package model

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type DbConf struct {
	Host     string
	Port     string
	DbName   string
	Username string
	Password string
}

var DB *gorm.DB

func Connect(connString string) {
	db, err := gorm.Open(mysql.Open(connString), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	sqlDB, err := db.DB()
	if err != nil {
		panic(err)
	}
	sqlDB.SetMaxIdleConns(10)
	sqlDB.SetMaxOpenConns(100)
	DB = db
	migration()
}
